require "selenium-webdriver"
require "test/unit"

class Roomsettings < Test::Unit::TestCase

	def text_from_file(filename)
		File.open(filename, 'r') { |f| f.read }
	end

	def sign_into_site(server, driver, file)
		driver.get server
		# sleep(1)
		driver.find_element(:link, "Sign-in").click
		begin
			account_name_field = driver.find_element :name => "ctl00$ContentPlaceHolder1$txtAccountName"
		rescue
			print "didn't find accountname for signing in, giving it an extra 5 seconds\n"
			sleep 5
			account_name_field = driver.find_element :name => "ctl00$ContentPlaceHolder1$txtAccountName"
		end
		account = text_from_file(file)
		account_name_field.send_keys account.split(":")[0]
		account_password_field = driver.find_element :name => "ctl00$ContentPlaceHolder1$txtPassword1"
		account_password_field.send_keys account.split(":")[1]
		signin_button = driver.find_element :id => "ctl00_ContentPlaceHolder1_btnSubmit"
		signin_button.click
	end

	def sign_out_of_site(server, driver)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
		element = wait.until { driver.find_element(:link_text => "signout") }
		element.click
	end

	def enter_a_random_room(driver, text_only)
		room = "test_" + Random.rand(1000).to_s()
		enter_room(driver, text_only, room)
	end

	def enter_room(driver, text_only, room)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
		room_name = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_txtRoomName") }
		room_name.send_keys room
		if ( text_only == true )
			room_select_button = driver.find_element :id => "ctl00_ContentPlaceHolder1_btnPhoneLogin"
		else
			room_select_button = driver.find_element :id => "ctl00_ContentPlaceHolder1_btnSelectRoom"
		end
		room_select_button.click

		sleep( 6 )
		nick_selection = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_txtUserName") }
		#nick_selection.send_keys :back,:back,:back,:back,:back,:back,:back,:back,:back,:back,:back,:back,:back,:back,:back
		nick_selection.clear
		nick_selection.send_keys "testing_selenium"

		room_entry_button = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_btnLogin") }
		room_entry_button.click
		sleep( 4 )
	end

	def leave_room(driver)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
		element = wait.until { driver.find_element(:link_text => "Leave") }
		element.click
		driver.get @server  # go back to the test server (if different than the live server)
	end

	def get_pop_up_window(driver)
		begin
			alert = driver.switch_to.alert
		rescue
			sleep 2
			begin
				alert = driver.switch_to.alert
			rescue
				sleep 2
				alert = driver.switch_to.alert
			end
		end
		alert
	end

	def send_text(driver, text_field, message, wait_for )
		if message != ""
			print "sending: " + message + "\n"
			text_field.send_keys message + "\n" #, :enter
		end
		if wait_for != ""
			got_it = false
			begin
				chat_history = driver.find_element :id => "txt"
				got_it = chat_history.text.include? wait_for
				if !got_it
					sleep 2
					chat_history = driver.find_element :id => "txt"
					got_it = chat_history.text.include? wait_for
				end
			rescue
				sleep 2
				chat_history = driver.find_element :id => "txt"
				got_it = chat_history.text.include? wait_for
			end

			if got_it
				print "  got: " + wait_for + "\n"
			else
				m = "didnt find: " +  wait_for + "\n"
				print m
				@verification_errors << m
			end
		end
	end

	def enter_bot_code(driver, chat_text, bot_source)
		sleep 1
		bot_text = driver.find_element :id => "botCode"
		send_text(driver, bot_text, bot_source, "")
		bot_btn = driver.find_element :id => "btnStartBot"
		bot_btn.click
		sleep 2
		got_it = driver.page_source.include? "Bot started."
		if got_it
			print "  started bot successfully\n"
		else
			m = "failed to start the bot\n"
			print m
			@verification_errors << m
		end
		# set focus back to the chat entry window
		chat_text.send_keys :escape
	end

	def chat_basic(server, driver, textonly)
		print "hello from test_chat_basic\n"
		enter_a_random_room(driver,false)

		chat_text = driver.find_element :id => "txtMsg"
		sleep 2
		send_text( driver, chat_text, "hello!", "hello!" )
		send_text( driver, chat_text, "camming up", "")

		if !textonly
			broadcast_btn = driver.find_element :link_text => "Broadcast!"
			broadcast_btn.click
			sleep 3
			send_text( driver, chat_text, "/cam on", "")
			sleep(1)
			send_text( driver, chat_text, "", "you are broadcasting")
		end

		send_text( driver, chat_text, "color test", "color test" )
		send_text( driver, chat_text, "/nick m0nk_3y_123", "testing_selenium is now m0nk_3y_123" )
		send_text( driver, chat_text, "hello1", "hello1" )
		send_text( driver, chat_text, "/nick m0nk_3y_123", "name is already" )
		send_text( driver, chat_text, "hello2", "hello2" )
		send_text( driver, chat_text, "/nick doodwtf_123", "m0nk_3y_123 is now doodwtf_123" )
		send_text( driver, chat_text, "hello3", "hello3" )
		send_text( driver, chat_text, "/nick digi_123", "doodwtf_123 is now digi_123" )
		send_text( driver, chat_text, "hello4", "hello4" )
		send_text( driver, chat_text, "/nick <iframe onload=\"alert('hi');\" ></iframe>", "digi_123 is now iframeonloadalerthiiframe" )
		send_text( driver, chat_text, "/nick test_123", "iframeonloadalerthiiframe is now test_123" )
		send_text( driver, chat_text, "hello5", "hello5" )
		send_text( driver, chat_text, "/help", "")
		send_text( driver, chat_text, "/oper test_123", "test_123 is already an operator" )
		send_text( driver, chat_text, "/cam refresh", "")
		send_text( driver, chat_text, "/cam down testtesttest", "does not appear to be on cam" )
		if !textonly
			send_text( driver, chat_text, "/cam down test_123", "test_123 has cammed down test_123" )
		end
		send_text( driver, chat_text, "/msg test_123 hello there in a whisper", "hello there in a whisper" )
		send_text( driver, chat_text, "/me is happy", "test_123 is happy" )
		send_text( driver, chat_text, "/ignore happy", "user not found" )
		send_text( driver, chat_text, "/ignore test_123", "You can't ignore yourself" )
		send_text( driver, chat_text, "/vog this is the voice-of-god command", "this is the voice-of-god command" )
		send_text( driver, chat_text, "/wog test_123 this is the whisper-of-god command", "this is the whisper-of-god command" )
		send_text( driver, chat_text, "you should get to work on making this http://i.imgur.com/KoyQ3.jpg the background image of the chat", "the background image of the chat" )
		send_text( driver, chat_text, "/msg test <iframe onload=\"alert('hi');\" ></iframe>", "" )
		send_text( driver, chat_text, "/kick <iframe onload=\"alert('hi');\" ></iframe>", "" )
		send_text( driver, chat_text, "/topic I like boobs", "has set the room topic to" )
		send_text( driver, chat_text, "/topic <iframe onload=\"alert('hi');\" ></iframe>", "" )
		send_text( driver, chat_text, "/privmsg test|<iframe onload=\"alert('hi');\" ></iframe>", "" )
		send_text( driver, chat_text, "/topic this is a new topic","has set the room topic to" )
		send_text( driver, chat_text, "/clear","" )
		send_text( driver, chat_text, "/back http://www.bostonherald.com/blogs/sports/rap_sheet/wp-content/uploads/2009/08/happy_birthday_cake.jpg", "must be hosted on vidble.com or imgur.com to prevent IP harvesting")
		send_text( driver, chat_text, "/topic this is a <b>new</b> topic","has set the room topic to")
		send_text( driver, chat_text, "/back", "test_123 has cleared the background image" )
		send_text( driver, chat_text, "/back http://www.bostsonherald.com/blogs/sports/rap_sheet/wp-content/uploads/2009/08/happy_birthday_cake.jpg", "" )

		send_text( driver, chat_text, "/bot-start", "" )
		enter_bot_code(driver, chat_text, "var bot_name = 'PMTestBot';\nvar bot_active = false;\nfunction botStart() { bot_active = true; }\nfunction botProcessLine( who, line ) { botSend( 'PUBLIC MESSAGE [' + who + '] said [' + line + ']' ); }\nfunction botProcessPM( who, line ) { botSend( 'PRIVATE MESSAGE [' + who + '] said [' + line + ']' ); }\n")
		send_text( driver, chat_text, "hallloooo", "PUBLIC MESSAGE [test_123] said [hallloooo]" )
		send_text( driver, chat_text, "/msg test_123 hullo", "PRIVATE MESSAGE [test_123] said [hullo]" )

		# close the PM box
		failed_pm = driver.find_element :id => "remove_test"
		failed_pm.click

		leave_room(driver)
	end

	def xss(server, driver)
		print 'hello from test_xss\n'
		enter_a_random_room(driver,false)

		chat_text = driver.find_element :id => "txtMsg"

		send_text( driver, chat_text, "http://'style='font-size:72px;color:#fff''onmouseover='x=\"\";s=\"\\x20\";$(\"#txtMsg\"+x).val(\"I\"+s+\"have\"+s+\"crabs\"+x);button_clicked();clearChatHistory();", "" )
		send_text( driver, chat_text, "http://'style='color:#fff''onmouseover='x=\"\";r=\"click\";s=\"\\x20\";$(this).fancybox({type:\"iframe\",href:\"http://www.youtube.com/v/ZuUxI6MEILU&autoplay=1\"}).trigger(r);$(this).remove();$(\"#txtMsg\"+x).val(\"dunce\"+x);button_clicked();'", "" )
		send_text( driver, chat_text, "http://'style='color:#fff''onmouseover='x=\"\";r=\"click\";s=\"\\x20\";$(this).fancybox({type:\"iframe\",href:\"http://www.youtube.com/v/qrBj3u5dPgM&autoplay=1\"}).trigger(r);$(this).remove();$(\"#txtMsg\"+x).val(\"x\"+x);button_clicked();'", "" )
		send_text( driver, chat_text, "http://'style='color:#fff''onmouseover='x=\"\";r=\"click\";s=\"\\x20\";$(this).fancybox({type:\"iframe\",href:\"http://www.youtube.com/v/4s0_QKL3O8s&autoplay=1\"}).trigger(r);$(this).remove();$(\"#txtMsg\"+x).val(\"x\"+x);button_clicked();'", "" )
		send_text( driver, chat_text, "http://'style='color:#fff''onmouseover='x=\"\";s=\"\\x20\";grr=$(\"div>b>a>img\"+x);grr.attr({src:\"http://i.imgur.com/CfBsF.gif\"});grr.animate({marginLeft:\"-=600px\"},13000);$(this).remove();'", "" )
		send_text( driver, chat_text, "http://'style='color:#ff''onmouseover='x=\"\";s=\"\\x20\";grr=$(\"div>b>a>img\"+x);grr.prependTo(\"body\"+x).attr({src:\"http://i.imgur.com/CfBsF.gif\"}).animate({marginLeft:\"+=600px\",height:\"200px\",width:\"200px\"},13000);$(this).remove();'", "" )
		send_text( driver, chat_text, "i iz dun h4x0ring... this one should come through as a valid hot link for other chatters in this room", "" )
		send_text( driver, chat_text, "http://www.americhip.com/cgi-bin/complex2/proddisp.pl?client=americhip&catid=17&PRID=109", "" )

		leave_room(driver)
	end


	def roomsettings_test(server, driver, account)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds

		message_text = "random text " + Random.rand(10000).to_s()
		room = "test_" + Random.rand(1000).to_s()

		trigger_text = "kickass trigger!"
		trigger_exact = "exact trigger "+ message_text + "[f1ber]" + trigger_text
		trigger_nonexact = "non-exact trigger " + message_text + "[f1ber]" + trigger_text

		enter_room(driver,false, room)

		driver.get(server + "/" + room + "/roomsettings")

		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtOwnerToAdd").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtOwnerToAdd").send_keys "m0nk_3y"
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_btnAddOwner").click
		assert_equal driver.page_source.include?("remove m0nk_3y"),true

		driver.find_element(:id, "ctl00_ContentPlaceHolder1_checkRegisteredAccountsOnly").click
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_checkNoNicksAllowed").click
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_checkDefaultToAudioOn").click
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_checkAutoBanForPrintScreen").click
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtWelcome").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtWelcome").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtRules").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtRules").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPasswords").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPasswords").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtSelfMods").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtSelfMods").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtOnMod").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtOnMod").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtModToModNotes").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtModToModNotes").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersExact").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersExact").send_keys trigger_exact
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersContain").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersContain").send_keys trigger_nonexact
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtDoNotMod").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtDoNotMod").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPermaBanned").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPermaBanned").send_keys message_text
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_btnSaveRoomSettings").click

		driver.get(server + "/" + room + "/roomsettings")
		wait.until { driver.page_source.include?("Room Settings") }

		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtWelcome").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtRules").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPasswords").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtSelfMods").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtOnMod").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtModToModNotes").text
		assert_equal trigger_exact, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersExact").text
		assert_equal trigger_nonexact, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtTriggersContain").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtDoNotMod").text
		assert_equal message_text, driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPermaBanned").text

		driver.get(server + "/" + room)
		#nick_selection = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_txtUserName") }
		sleep 5

		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtPassword").send_keys message_text

		room_entry_button = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_btnLogin") }
		room_entry_button.click

		wait.until { driver.title.downcase.start_with? room }

		wait = Selenium::WebDriver::Wait.new(:timeout => 3) # seconds
		chat_text = driver.find_element :id => "txtMsg"
		sleep 2
		send_text( driver, chat_text, "/nick fh90askd1k2eh", "This room is configured by the owner to not allow nick changes" )
		send_text( driver, chat_text, "exact trigger "+ message_text, trigger_text )
		sleep 3
		send_text( driver, chat_text, "this is a non-exact trigger "+ message_text, trigger_text )
		#send_text( driver, chat_text, "this is a non-exact trigger "+ message_text, "seconds (there is a 30 second block window to minimize flooding/abuse)]" )
		leave_room(driver)
	end

	def send_message(server, driver, account, message)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
		acc = text_from_file(account).split(":")[0]
		driver.get server + "/user/" + acc

		#this sucks, there must be a better way to work around these lameass generated id's
		send_message_btn = wait.until { driver.find_element :id => "ctl00_ContentPlaceHolder1_btnSendMessage" }
		send_message_btn.click

		wait.until { driver.find_element :id => "ctl00_ContentPlaceHolder1_txtNewMessage" }
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtNewMessage").clear
		driver.find_element(:id, "ctl00_ContentPlaceHolder1_txtNewMessage").send_keys message

		sleep 3

		driver.find_element(:id, "ctl00_ContentPlaceHolder1_btnSendMessage").click

		#sleep 1

		wait.until { driver.title.downcase.start_with? "messages" }

		sleep 1
	end

	def check_message_thread(server, driver, account, message)
		acc = text_from_file(account).split(":")[0]
		wait = Selenium::WebDriver::Wait.new(:timeout => 5) # seconds
	#	wait.until { driver.title.downcase.start_with? "icanhazchat" }

		# do we have unread messages? BUGGY, DOESNT ALWAYS EXIST!
		begin
			element = driver.find_element :id => "unread_mess"
		rescue
			@verification_errors << "no unread messages"
		end

		element = wait.until { driver.find_element(:link_text => "messages") }
		element.click

		driver.execute_script("open_message('" + acc + "')")
		wait.until { driver.title.downcase.start_with? acc }

		assert_equal driver.page_source.include?(message),true
	end

	def delete_message_thread(server, driver, account)
		wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
		acc = text_from_file(account).split(":")[0]
		driver.get server + "/messages/" + acc

		#tried to use alt-x before, but then switching to alert fails.
		element = wait.until { driver.find_element(:id => "ctl00_ContentPlaceHolder1_btnDeleteThread") }
		element.click()
		alert = get_pop_up_window(driver)
		if !alert.text.include?("Delete this message thread?") then
			log_error("Pop up alert when deleting messages contained unexpected text [" + alert.text + "]")
			sleep 5
		end
		alert.accept
	end

	def try_onetime_payment(server, driver, amount, card, cvc, month, year, zip_code, expected_response)
		driver.get server + "/gethearted"
		amt = driver.find_element :class => "payment-amt"
		amt.clear
		amt.send_keys amount

		driver.find_element(:class => "card-number-onetime").send_keys card
		driver.find_element(:class => "card-cvc-onetime").send_keys cvc
		driver.find_element(:class => "card-expiry-month-onetime").send_keys month
		driver.find_element(:class => "card-expiry-year-onetime").send_keys year
		driver.find_element(:class => "billing-zip-code-onetime").send_keys zip_code, :enter
		sleep 4

		if !driver.page_source.include?(expected_response) then
			print "Submitting one time payment failed to get expected response [" + expected_response + "]\n"
			sleep 3
			if !driver.page_source.include?(expected_response) then
				print "Submitting one time payment failed to get expected response [" + expected_response + "]\n"
				crash_here
			end
		end
	end

	def try_monthly_payment(server, driver, amount, card, cvc, month, year, zip_code, expected_response)
		driver.get server + "/gethearted"
		amt = driver.find_element :class => "payment-amt"
		amt.clear
		amt.send_keys amount

		driver.find_element(:class => "card-number").send_keys card
		driver.find_element(:class => "card-cvc").send_keys cvc
		driver.find_element(:class => "card-expiry-month").send_keys month
		driver.find_element(:class => "card-expiry-year").send_keys year
		driver.find_element(:class => "billing-zip-code").send_keys zip_code, :enter
		sleep 4

		if !driver.page_source.include?(expected_response) then
			print "Submitting monthly payment failed to get expected response [" + expected_response + "]\n"
			sleep 3
			if !driver.page_source.include?(expected_response) then
				print "Submitting monthly payment failed to get expected response [" + expected_response + "]\n"
				crash_here
			end
		end
	end


	def try_monthly_payment_failure(server, driver, amount, card, cvc, month, year, zip_code, expected_response)
		driver.get server + "/gethearted"
		amt = driver.find_element :class => "payment-amt"
		amt.clear
		amt.send_keys amount

		driver.find_element(:class => "card-number").send_keys card
		driver.find_element(:class => "card-cvc").send_keys cvc
		driver.find_element(:class => "card-expiry-month").send_keys month
		driver.find_element(:class => "card-expiry-year").send_keys year
		driver.find_element(:class => "billing-zip-code").send_keys zip_code, :enter
		sleep 2

		#alert = get_pop_up_window( driver )
		#alert_text = alert.text
		#alert.accept

		alert = driver.find_element(:class => "modal")
		alert_text = alert.text
		#driver.send_keys :escape
		driver.find_element(:class => "card-number").send_keys :escape

		if !alert_text.include?(expected_response) then
			print "Submitting monthly payment failed to get expected ERROR response [" + expected_response + "], got [" + alert_text + "] instead\n"
			crash_here
		end
	end

	def payments(server, driver)

		## BUGBUG - need to pick the right date from the combo box / select
		try_monthly_payment(server, driver, "12.99", "4242424242424242", "1234", "12", "2014", "10467", "Thank you!" )
		try_onetime_payment(server, driver, "3.00", "4242424242424242", "1234", "12", "2014", "10467", "Thank you!" )

		## try the error cases
		try_monthly_payment_failure(server, driver, "12.99", "4242424242424242", "1234", "12", "2010", "10467", "Your card's expiration year is invalid" ) # wrong year
		try_monthly_payment_failure(server, driver, "12.99", "4242424242424242", "1234", "13", "2014", "10467", "Your card's expiration month is invalid" ) # wrong month
		try_monthly_payment_failure(server, driver, "12.99", "4242424242424242", "12", "12", "2014", "10467", "Your card's security code is invalid" ) # wrong crc
		try_monthly_payment_failure(server, driver, "12.99", "4242424242424241", "1234", "12", "2014", "10467", "Your card number is incorrect" ) # wrong card

		# mark the messages as unread (so they don't pop-up in chat)
		@driver.get @server
		driver.find_element(:link, "messages").click
	end

	def tc_payments
		payments(@server, @driver)
		@driver.get @server
	end

	def tc_offline_messaging
		message_text = "random text " + Random.rand(10000).to_s()
		self.sign_into_site(@server, @driver, @account1)
		self.send_message(@server, @driver, @account2, message_text)
		self.sign_out_of_site(@server,@driver)
		self.sign_into_site(@server, @driver, @account2)
		self.check_message_thread(@server, @driver, @account1, message_text)
		self.delete_message_thread(@server, @driver, @account1)
		self.sign_out_of_site(@server, @driver)
	end

	def tc_chat_basic
		self.chat_basic(@server, @driver, false)
	end

	def tc_textonly
		self.chat_basic(@server, @driver, true)
	end

	def tc_roomsettings
		self.roomsettings_test(@server, @driver, @account1)
	end

	def tc_xss
		self.xss(@server, @driver)
	end

	def tc_ichc
		@account1 = "account1.txt"
		@account2 = "account2.txt"

		@server = self.text_from_file("server_to_test.txt")
		@driver.manage.timeouts.implicit_wait = 30
		@verification_errors = []

		self.sign_into_site(@server, @driver, @account1)
		tc_chat_basic
		tc_payments
		tc_xss
		tc_roomsettings
		tc_textonly
		self.sign_out_of_site(@server, @driver)
		tc_offline_messaging
	end

	#def test_ie
	#	@driver = Selenium::WebDriver.for :ie
	#	tc_ichc
	#end

	def test_chrome
		@driver = Selenium::WebDriver.for :chrome
		tc_ichc
	end

	def test_firefox
		@driver = Selenium::WebDriver.for :firefox
		tc_ichc()
	end

	def setup
		@account1 = "account1.txt"
		@account2 = "account2.txt"
	end

	def teardown
		@driver.quit
		assert_equal [], @verification_errors
	end

	def element_present?(how, what)
		@driver.find_element(how, what)
		true
		rescue Selenium::WebDriver::Error::NoSuchElementError
		false
	end

	def verify(&blk)
		yield
		rescue Test::Unit::AssertionFailedError => ex
		@verification_errors << ex
	end
end
